#include "common.h"
void show_word(int x0, int y0, int w, int h, unsigned char word[][w / 8], int color)
{
    int i, j, k;
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w / 8; j++)
        {
            // 解析 word[i][j] 的8个bits位，为1就显示颜色，为0就不显示
            for (k = 7; k >= 0; k--)
            {
                if (word[i][j] & (1 << k))
                {
                    // 画点
                    display_point(j * 8 + (7 - k) + x0, i + y0, color);
                }
            }
        }
    }
}
unsigned char numbers[10][31][16 / 8] = {
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x1F, 0xE0,
     0x3F, 0xF0, 0x3C, 0x78, 0x78, 0x78, 0x78, 0x78, 0x70, 0x3C, 0xF0, 0x3C, 0xF0, 0x3C, 0xF0, 0x3C,
     0xF0, 0x3C, 0xF0, 0x3C, 0xF0, 0x3C, 0x70, 0x38, 0x78, 0x78, 0x78, 0x78, 0x3C, 0xF0, 0x3F, 0xF0,
     0x1F, 0xE0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x03, 0xC0,
     0x0F, 0xC0, 0x3F, 0xC0, 0x3F, 0xC0, 0x33, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0,
     0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0,
     0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x3F, 0xE0,
     0x7F, 0xF0, 0x78, 0xF8, 0x60, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0xF0, 0x01, 0xF0,
     0x03, 0xE0, 0x0F, 0xC0, 0x1F, 0x00, 0x3E, 0x00, 0x3C, 0x00, 0x78, 0x00, 0x78, 0x00, 0x7F, 0xFC,
     0x7F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

    },
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x3F, 0xE0,
     0x3F, 0xF0, 0x30, 0xF0, 0x00, 0xF0, 0x00, 0x70, 0x00, 0xF0, 0x00, 0xF0, 0x1F, 0xE0, 0x1F, 0xC0,
     0x1F, 0xF0, 0x00, 0xF0, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x70, 0xF0, 0x7F, 0xF0,
     0x7F, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0xF0,
     0x01, 0xF0, 0x03, 0xF0, 0x03, 0xF0, 0x07, 0xF0, 0x0F, 0xF0, 0x0E, 0xF0, 0x1E, 0xF0, 0x3C, 0xF0,
     0x78, 0xF0, 0x78, 0xF0, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0xF0,
     0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

    },
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xF0, 0x3F, 0xF0,
     0x3F, 0xF0, 0x3C, 0x00, 0x3C, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x3F, 0xC0, 0x3F, 0xF0,
     0x01, 0xF0, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x70, 0xF0, 0x7F, 0xF0,
     0x7F, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF0, 0x0F, 0xF8,
     0x1F, 0xF8, 0x1E, 0x00, 0x3C, 0x00, 0x38, 0x00, 0x78, 0x00, 0x7B, 0xC0, 0x7F, 0xF0, 0x7F, 0xF8,
     0x7C, 0x78, 0x78, 0x3C, 0x78, 0x3C, 0x78, 0x3C, 0x78, 0x3C, 0x78, 0x38, 0x3C, 0x78, 0x3F, 0xF0,
     0x1F, 0xE0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF8, 0x7F, 0xFC,
     0x7F, 0xF8, 0x00, 0x78, 0x00, 0x70, 0x00, 0xF0, 0x00, 0xE0, 0x01, 0xE0, 0x01, 0xC0, 0x03, 0xC0,
     0x03, 0x80, 0x07, 0x80, 0x07, 0x80, 0x07, 0x00, 0x0F, 0x00, 0x0F, 0x00, 0x0F, 0x00, 0x1E, 0x00,
     0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x1F, 0xE0,
     0x3F, 0xF0, 0x3C, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x3C, 0xF0, 0x1F, 0xE0, 0x1F, 0xE0,
     0x3F, 0xF0, 0x78, 0x78, 0x70, 0x38, 0xF0, 0x3C, 0xF0, 0x3C, 0x70, 0x38, 0x78, 0x78, 0x3F, 0xF0,
     0x1F, 0xE0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

    },
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x1F, 0xE0,
     0x3F, 0xF0, 0x78, 0xF8, 0x78, 0x78, 0x70, 0x78, 0xF0, 0x38, 0xF0, 0x3C, 0x78, 0x7C, 0x7C, 0xFC,
     0x3F, 0xFC, 0x1F, 0xF8, 0x07, 0x38, 0x00, 0x78, 0x00, 0x78, 0x00, 0xF0, 0x21, 0xF0, 0x7F, 0xE0,
     0x7F, 0xC0, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

    },
};
void show_num(int x0, int y0, int number)
{
    // int num[100];
    //  int n = 0;
    //  do
    //  {
    //      num[n++] = number%10;
    //      number = number/10;
    //  } while (number);
    //  for(int i = n-1;i>=0;i--)
    //  {
    //      show_word(x0, y0, 16, 31, numbers[num[i]],0x000000);
    //      x0 += 18;

    // }
    int num[20] = {0}, i = 19;
    while (number)
    {
        num[i] = number % 10;
        i--;
        number /= 10;
    }
    i = 0;
    while (num[i] == 0)
        i++;
    for (; i < 20; i++)
    {
        show_word(transact(x0), transact(y0), 16, 31, numbers[num[i]], 0x000000);
        x0 += 18;
    }
}
void show_float(int x0, int y0, double number)
{
    // int zs = number;
    // int x = zs,i = 0;;
    // show_num(transact(x0), transact(y0),zs);
    // do
    // {
    //     x/=10;
    //     i++;
    //     /* code */
    // } while (x/* condition */);
    // show_word(transact(x0)+i*17, transact(y0), 16, 29, dot, 0x000000);
    // int xs = number*100;
    // show_num(transact(x0)+i*17+15, transact(y0), xs);

    int num[20] = {0}, i = 19;
    number *= 100;
    int int_num = (int)number;
    // while (int_num)
    // {
    //     num[i] = int_num % 10;
    //     i--;
    //     int_num /= 10;

    //     i = 0;
    //     while (num[i] == 0 && i < 18)
    //         i++;
    //     for (; i < 18; i++)
    //     {
    //         show_word(transact(x0), transact(y0), 16, 31, numbers[num[i]], 0x000000);
    //         x0 += 16;
    //     }
    //     show_word(transact(x0), transact(y0), 16, 29, dot, 0x000000);
    //     x0 += 14;
    //     for (; i < 20; i++)
    //     {
    //         show_word(transact(x0), transact(y0), 16, 31, numbers[num[i]], 0x000000);
    //         x0 += 16;
    //     }
    // }
    i = 19;
    do
    {
        num[i--] = int_num % 10;
        int_num /= 10;

    } while (int_num);
    if (i > 17)
        i = 17;
    else
        i++;
    for (; i < 20; i++)
    {
        if (i == 18)
        {
            show_word(transact(x0), transact(y0), 16, 29, dot, 0x000000);
            x0 += 14;
        }

        {
            show_word(transact(x0), transact(y0), 16, 31, numbers[num[i]], 0x000000);
            x0 += 17;
        }
    }
}
// void count_down(int x0, int y0, int number)
// {
//     while (number--)
//     {
//         // show_word(x0, y0, 16, 31, number,0x000000);
//         show_num(x0, y0, number);
//         sleep(1);
//         show_a_color(0xffffff);
//     }
// }
